package com.learn.base;

/**
 * 结果：原子的，可见的，非顺序的
 */
public class SendMoneySynchronized {
    private int mAcount = 0;
    public SendMoneySynchronized() {

    }
    public void sendMoney(int time,int money, String tName) {
        synchronized (this) {
            try {
                Thread.sleep(100);
                mAcount += money;
                System.out.println("线程：" + tName + "，第【" + time + "】次存钱，账户=" + mAcount);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void saveMoney(int time,int money, String tName) {
        try {
            Thread.sleep(100);
            mAcount +=  money;
            System.out.println("线程：" + tName + "，第【" + time + "】次存钱，账户=" + mAcount);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public Integer getAccout() {
        System.out.println("Accout:"+mAcount);
        return mAcount;
    }
}
